# Maintainer: Andrew Sun <adsun701@gmail.com>
_realname=json-rpc
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python2-${_realname}"  "${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=1.11.0
pkgrel=1
pkgdesc="JSON-RPC transport realisation (mingw-w64)"
arch=('any')
url="https://github.com/pavlov99/json-rpc"
license=('MIT')
makedepends=("${MINGW_PACKAGE_PREFIX}-python2"
             "${MINGW_PACKAGE_PREFIX}-python3"
             "${MINGW_PACKAGE_PREFIX}-python3-setuptools"
             "${MINGW_PACKAGE_PREFIX}-python2-setuptools")
options=('staticlibs' 'strip' '!debug')
source=("https://pypi.python.org/packages/source/j/${_realname}/${_realname}-${pkgver}.tar.gz")
sha256sums=('a5e53f80699e97754bfd8a29c86138aa144c4e6663fe80c0be5270fc6f177166')

prepare() {  
  cd "${srcdir}"
  for pver in {2,3}; do 
    rm -rf python${pver}-build-${CARCH} | true
    cp -r "${_realname}-${pkgver}" "python${pver}-build-${CARCH}"
  done  
}  
  
build() {
  cd "${srcdir}"
  for pver in {2,3}; do  
    msg "Python ${pver} build for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py build
  done  
}

check() {
  cd "${srcdir}"
  for pver in {2,3}; do  
    msg "Python ${pver} test for ${CARCH}"  
    cd "${srcdir}/python${pver}-build-${CARCH}"
    ${MINGW_PREFIX}/bin/python${pver} setup.py test
  done  
}

package_python3-json-rpc() {
  depends=("${MINGW_PACKAGE_PREFIX}-python3")

  cd "${srcdir}/python3-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python3 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}

package_python2-json-rpc() {
  depends=("${MINGW_PACKAGE_PREFIX}-python2")

  cd "${srcdir}/python2-build-${CARCH}"
  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python2 setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build
}

package_mingw-w64-i686-python2-json-rpc() {
  package_python2-json-rpc
}

package_mingw-w64-i686-python3-json-rpc() {
  package_python3-json-rpc
}

package_mingw-w64-x86_64-python2-json-rpc() {
  package_python2-json-rpc
}

package_mingw-w64-x86_64-python3-json-rpc() {
  package_python3-json-rpc
}
